//
//  PagingViewTableHeaderView.swift
//  JXPagingView
//
//  Created by jiaxin on 2018/5/28.
//  Copyright © 2018年 jiaxin. All rights reserved.
//

import UIKit

protocol PagingViewTableHeaderViewDelegate: NSObjectProtocol {
    func textFieldShouldBeginEditing(_ textField: UITextField)
}

extension PagingViewTableHeaderView: MTClubSearchBarViewDelegate {
    func textFieldShouldBeginEditing(_ textField: UITextField) {
        self.delegate?.textFieldShouldBeginEditing(textField)
    }
}

class PagingViewTableHeaderView: UIView {
    var searchBarView: MTClubSearchBarView = MTClubSearchBarView()
    var searchBarViewFrame: CGRect = CGRect.zero
    
    weak var delegate: PagingViewTableHeaderViewDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(hex: 0xf4f4f4)
        
        addSubview(searchBarView)
        
        searchBarView.delegate = self
        
        searchBarView.snp.makeConstraints { (make) in
            make.top.left.equalToSuperview().offset(10)
            make.bottom.right.equalToSuperview().offset(-10)
        }
    }
    
    convenience init(title: String) {
        self.init(frame: .zero)
        self.searchBarView.title = title
    }

    override func layoutSubviews() {
        super.layoutSubviews()

        //searchBarViewFrame = bounds
    }

//    func scrollViewDidScroll(contentOffsetY: CGFloat) {
//        var frame = searchBarViewFrame
//        frame.size.height -= contentOffsetY
//        frame.origin.y = contentOffsetY
//        searchBarView.frame = frame
//    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
